﻿Imports lbGlobalcom

Public Class fBodegas
    Dim daBodegas As lbGlobalcom.dsInventariosTableAdapters.INV_BODEGASTableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    Private Sub LLenaSedes()
        Try
            Dim daSedes As New lbGlobalcom.dsGlobalTableAdapters.GLO_SEDESTableAdapter
            daSedes.Fill(Me.DsGlobal.GLO_SEDES)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try

    End Sub

    Private Sub INV_BODEGASBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INV_BODEGASBindingNavigatorSaveItem.Click
        Try
            Validate()
            INV_BODEGASBindingSource.EndEdit()
            daBodegas.Update(DsInventarios.INV_BODEGAS)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub fBodegas_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsInventarios.INV_BODEGAS.GetChanges() IsNot Nothing Then
                INV_BODEGASBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    INV_BODEGASBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub fBodegas_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
            daBodegas = New lbGlobalcom.dsInventariosTableAdapters.INV_BODEGASTableAdapter
            LLenaSedes()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub INV_BODEGASDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles INV_BODEGASDataGridView.CellBeginEdit
        If e.ColumnIndex = 1 AndAlso INV_BODEGASDataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
            Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
            dt = daClave.GetDataByIdClavePrimaria("INV_BODEGAS")
            If dt.Count Then
                Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                dr = dt.Rows(0)
                Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                INV_BODEGASDataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                Cons = Nothing
                INV_BODEGASBindingSource.EndEdit()
                daBodegas.Update(DsInventarios.INV_BODEGAS)
            End If
        End If
    End Sub

    Private Sub INV_BODEGASDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles INV_BODEGASDataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub INV_BODEGASDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles INV_BODEGASDataGridView.UserDeletedRow
        Try
            daBodegas.Update(DsInventarios.INV_BODEGAS)
            MessageBox.Show("Se elimino registro con exito", "Elimina Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try

    End Sub

    Private Sub INV_BODEGASDataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles INV_BODEGASDataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que dese eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

    Private Sub btnCargar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargar.Click
        Try
            If Me.DsInventarios.INV_BODEGAS.GetChanges() IsNot Nothing Then
                INV_BODEGASBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    INV_BODEGASBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daBodegas.FillBySedes(DsInventarios.INV_BODEGAS, CustomPrincipal.GetSede & "%")
            'daBodegas.Fill(DsInventarios.INV_BODEGAS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
End Class